﻿using Lamex.Common;
using Lamex.Core;
using Lamex.Interface;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lamex.Library
{
    public partial class frmBaseChild : frmBase, IMdiChildForm
    {
        /// <summary>
        /// 父窗体的Toolbar组件
        /// </summary>
        protected IToolbarRegister _ToolbarRegister = null;
        /// <summary>
        /// 初始化子窗体的按钮
        /// </summary>
        protected IButtonList _buttons = new ButtonList();
        /// <summary>
        /// 子窗体观察者
        /// </summary>
        protected IList _observers = new ArrayList();
        /// <summary>
        /// 子窗体系统按钮
        /// </summary>
        protected IButtonInfo[] _SystemButtons = null;
        /// <summary>
        /// 窗体是否正在关闭装态
        /// </summary>
        protected bool _IsClosing = false;
        /// <summary>
        /// 是否只保留一个子窗体实例
        /// </summary>
        protected bool _AllowMultiInstance = false;
        /// <summary>
        /// 窗体的可用权限
        /// </summary>
        protected int _FormAuthorities = 0;
        /// <summary>
        /// 打开窗体的菜单名
        /// </summary>
        protected string _FormMenuName = "";
        public frmBaseChild()
        {
            InitializeComponent();
            
        }

        //region IPurviewControllable接口实现
        /// <summary>
        /// 窗体可能权限为2^n方:1,2,4,8,16...n^2
        /// 打开窗体时从数据库获取权限值保存在该变量
        /// </summary>
        public int FormAuthorities { get { return _FormAuthorities; } set { _FormAuthorities = value; } }
        /// <summary>
        /// 打开窗体的菜单名
        /// </summary>
        public string FormMenuName { get { return _FormMenuName; } set { _FormMenuName = value; } }
        /// <summary>
        /// 系统是否保留一个窗体实例
        /// </summary>
        /// <param name="authorityValue"></param>
        /// <returns></returns>
        public virtual bool ButtonAuthorized(int authorityValue) { return false; }
        /// <summary>
        /// 检查当前用户是否拥有本窗体的特定权限
        /// </summary>
        /// <param name="value">需要需要检查的权限值</param>
        /// <returns></returns>
        public bool HasPurview(int value)
        {
            return (value & _FormAuthorities) == value;
        }
        /// <summary>
        /// 可以通过外部调用该方法重新设置按钮权限
        /// </summary>
        public virtual void SetButtonAuthority()
        {

        }
       

        #region "IMdiChildForm"接口实现
        /// <summary>
        /// 主窗体的Toolbar按钮注册器 
        /// </summary>
        public IToolbarRegister ToolbarRegister
        {
            get { return _ToolbarRegister; }
            set { _ToolbarRegister = value; }
        }

        public virtual void RegisterToolBar(IToolbarRegister toolBarRegister)
        {
            toolBarRegister.RegisteButton(this._buttons.ToList());
        }
        /// <summary>
        /// 当前窗体是否正在关闭状态
        /// </summary>
        public bool IsClosing { get { return _IsClosing; } set { _IsClosing = value; } }
        /// <summary>
        /// 注册子窗体观察者
        /// </summary>
        /// <param name="observers"></param>
        public void RegisterObserver(IObserver[] observers)
        {
            foreach (IObserver o in observers)
                _observers.Add(o);
        }

        /// <summary>
        /// 子窗体的按钮数组
        /// </summary>
        public IButtonList Buttons { get { return _buttons; } }
        /// <summary>
        /// 模板方法.初始化本窗体的按钮
        /// </summary>
        public virtual void InitButtons()
        {
            try
            {
                IButtonInfo[] bi = GetDataOperatableButtons();
                this.Buttons.AddRange(bi);
            }
            catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
        }
        /// <summary>
        /// 系统按钮列表。注：子窗体享用系统按钮，如帮助/关闭窗体常用功能。
        /// </summary>
        /// <returns></returns>
        public virtual IButtonInfo[] GetSystemButtons()
        {
            if (_SystemButtons == null)
            {
                _SystemButtons = new IButtonInfo[2];
                _SystemButtons[0] = this.ToolbarRegister.CreateButton("btnHelp(&H)", "帮助",
                    Globals.LoadBitmap("24_Help.ico"), new Size(57, 28), this.DoHelp,"");
                _SystemButtons[1] = this.ToolbarRegister.CreateButton("btnClose(&O)", "关闭",
                    Globals.LoadBitmap("24_Exit.ico"), new Size(57, 28), this.DoClose,"");

            }
            return _SystemButtons;
        }
        public IButtonInfo[] GetDataOperatableButtons()
        {
            //DataTable dt = ;
            ArrayList list = new ArrayList();
            if (Loginer.CurrentUser.ChangeLanguage == 0)
            {


                DataRow Row = SystemAuthentication.UserAuthorities.Select("ID='" + Loginer.CurrentUser.FunctionId + "'").FirstOrDefault();

                if (Row != null)
                {
                    DataRow[] dRows = SystemAuthentication.UserAuthorities.Select("PID='" + Row["ID"].ToString() + "'").OrderBy(x => x["SortCode"]).ToArray(); ;
                    if (dRows != null)
                    {
                        foreach (DataRow dr in dRows)
                        {
                            if (dr["AuthorityID"].ToString() == "btnView")
                            {

                                list.Add(this.ToolbarRegister.CreateButton("btnView", dr["FunName"].ToString() + "(&Q)", Resource._24_ViewContent.ToBitmap(), new Size(57, 28), this.DoView, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnAdd")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnAdd", dr["FunName"].ToString() + "(&N)", Resource._24_Add.ToBitmap(), new Size(57, 28), this.DoAdd, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnDelete")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnDelete", dr["FunName"].ToString() + "(&E)", Resource._24_Delete.ToBitmap(), new Size(57, 28), this.DoDelete, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnEdit")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnEdit", dr["FunName"].ToString() + "(&D)", Resource._24_Edit.ToBitmap(), new Size(57, 28), this.DoEdit, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnSave")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnSave", dr["FunName"].ToString() + "(&S)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoSave, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnExport")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnExport", dr["FunName"].ToString() + "(&O)", Resource._24_Export.ToBitmap(), new Size(57, 28), this.DoExport, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnImport")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnImport", dr["FunName"].ToString() + "(&I)", Resource._24_Export.ToBitmap(), new Size(57, 28), this.DoImport, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnPrint")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnPrint", dr["FunName"].ToString() + "(&P)", Resource._24_PrintPreview.ToBitmap(), new Size(57, 28), this.DoPrint, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnColse")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnColse", dr["FunName"].ToString() + "(&C)", Resource._24_PrintPreview.ToBitmap(), new Size(57, 28), this.DoClose, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnReturn")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnReturn", dr["FunName"].ToString() + "(&R)", Resource._24_PrintPreview.ToBitmap(), new Size(57, 28), this.DoReturn, dr["ID"].ToString()));
                            }

                            else if (dr["AuthorityID"].ToString() == "btnCalculate")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnCalculate", dr["FunName"].ToString() + "(&J)", Resource._24_Calculate.ToBitmap(), new Size(57, 28), this.DoCalculate, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnSJ")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnSJ", dr["FunName"].ToString() + "(&S)", Resource.SJ.ToBitmap(), new Size(57, 28), this.DoSJ, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnSTD")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnSTD", dr["FunName"].ToString() + "(&T)", Resource.SJ.ToBitmap(), new Size(57, 28), this.DoSTD, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnMachineTime")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnMachineTime", dr["FunName"].ToString() + "(&J)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoMachineTime, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnUnCheck")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnUnCheck", dr["FunName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoUnCheck, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnCheck")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnCheck", dr["FunName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoCheck, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnUpLoad")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnUpLoad", dr["FunName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoUpLoad, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnIEExportUpLoad")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnIEExportUpLoad", dr["FunName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoIEExportUpLoad, dr["ID"].ToString()));

                            }
                            else if (dr["AuthorityID"].ToString() == "btnIECalcuate")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnIECalcuate", dr["FunName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoIECalcuate, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnResetCom")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnResetCom", dr["FunName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoResetCom, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnUpLoadSAP")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnUpLoadSAP", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoUpLoadSAP, dr["ID"].ToString()));

                            }
                            else if (dr["AuthorityID"].ToString() == "btnStaff")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnStaff", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DOStaffConfigure, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnChange")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnChange", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DOChange, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton1")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton1", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton1, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton2")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton2", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton2, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton3")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton3", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton3, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton4")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton4", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton4, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton5")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton5", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton5, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton6")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton6", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton6, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnFeatureImport")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnFeatureImport", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoFeatureImport, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnUnLocked")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnUnLocked", dr["FunName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoUnLocked, dr["ID"].ToString()));
                            }

                            else if (dr["AuthorityID"].ToString() == "btnApproval")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnApproval", dr["FunName"].ToString(), Resource.shenpi, new Size(57, 28), this.DoApproval, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnDeclare")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnDeclare", dr["FunName"].ToString(), Resource.shenbao, new Size(57, 28), this.DoDeclare, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBack")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBack", dr["FunName"].ToString(), Resource.tuihui, new Size(57, 28), this.DoBack, dr["ID"].ToString()));
                            }

                        }
                    }
                }


            }
            else
            {
                DataRow Row = SystemAuthentication.UserAuthorities.Select("ID='" + Loginer.CurrentUser.FunctionId + "'").FirstOrDefault();

                if (Row != null)
                {
                    DataRow[] dRows = SystemAuthentication.UserAuthorities.Select("PID='" + Row["ID"].ToString() + "'").OrderBy(x => x["SortCode"]).ToArray(); ;
                    if (dRows != null)
                    {
                        foreach (DataRow dr in dRows)
                        {
                            if (dr["AuthorityID"].ToString() == "btnView")
                            {

                                list.Add(this.ToolbarRegister.CreateButton("btnView", dr["EngName"].ToString() + "(&Q)", Resource._24_ViewContent.ToBitmap(), new Size(57, 28), this.DoView, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnAdd")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnAdd", dr["EngName"].ToString() + "(&N)", Resource._24_Add.ToBitmap(), new Size(57, 28), this.DoAdd, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnDelete")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnDelete", dr["EngName"].ToString() + "(&E)", Resource._24_Delete.ToBitmap(), new Size(57, 28), this.DoDelete, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnEdit")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnEdit", dr["EngName"].ToString() + "(&D)", Resource._24_Edit.ToBitmap(), new Size(57, 28), this.DoEdit, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnSave")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnSave", dr["EngName"].ToString() + "(&S)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoSave, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnExport")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnExport", dr["EngName"].ToString() + "(&O)", Resource._24_Export.ToBitmap(), new Size(57, 28), this.DoExport, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnImport")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnImport", dr["EngName"].ToString() + "(&I)", Resource._24_Export.ToBitmap(), new Size(57, 28), this.DoImport, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnPrint")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnPrint", dr["EngName"].ToString() + "(&P)", Resource._24_PrintPreview.ToBitmap(), new Size(57, 28), this.DoPrint, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnColse")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnColse", dr["EngName"].ToString() + "(&C)", Resource._24_PrintPreview.ToBitmap(), new Size(57, 28), this.DoClose, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnReturn")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnReturn", dr["EngName"].ToString() + "(&R)", Resource._24_PrintPreview.ToBitmap(), new Size(57, 28), this.DoReturn, dr["ID"].ToString()));
                            }

                            else if (dr["AuthorityID"].ToString() == "btnCalculate")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnCalculate", dr["EngName"].ToString() + "(&J)", Resource._24_Calculate.ToBitmap(), new Size(57, 28), this.DoCalculate, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnSJ")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnSJ", dr["EngName"].ToString() + "(&S)", Resource.SJ.ToBitmap(), new Size(57, 28), this.DoSJ, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnSTD")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnSTD", dr["EngName"].ToString() + "(&S)", Resource.SJ.ToBitmap(), new Size(57, 28), this.DoSTD, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnMachineTime")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnMachineTime", dr["EngName"].ToString() + "(&J)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoMachineTime, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnUnCheck")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnUnCheck", dr["EngName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoUnCheck, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnCheck")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnCheck", dr["EngName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoCheck, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnUpLoad")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnUpLoad", dr["EngName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoUpLoad, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnIEExportUpLoad")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnIEExportUpLoad", dr["EngName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoIEExportUpLoad, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnIECalcuate")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnIECalcuate", dr["FunName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoIECalcuate, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnResetCom")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnResetCom", dr["EngName"].ToString() + "(&F)", Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoResetCom, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnUpLoadSAP")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnUpLoadSAP", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoUpLoadSAP, dr["ID"].ToString()));

                            }
                            else if (dr["AuthorityID"].ToString() == "btnStaff")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnStaff", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DOStaffConfigure, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnChange")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnChange", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DOChange, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton1")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton1", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton1, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton2")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton2", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton2, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton3")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton3", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton3, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton4")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton4", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton4, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton5")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton5", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton5, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnBotton6")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnBotton6", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoButton6, dr["ID"].ToString()));
                            }
                            else if (dr["AuthorityID"].ToString() == "btnUnLocked")
                            {
                                list.Add(this.ToolbarRegister.CreateButton("btnUnLocked", dr["EngName"].ToString(), Resource._24_Save.ToBitmap(), new Size(57, 28), this.DoUnLocked, dr["ID"].ToString()));
                            }
                        }
                    }
                }
            }

            IButtonInfo[] ii = (IButtonInfo[])list.ToArray(typeof(IButtonInfo));
            return ii;
        }
        public virtual void DoView(IButtonInfo sender)
        {
            //Msg.AskQuestion("帮助文档");
        }
        public virtual void DoAdd(IButtonInfo sender)
        {
            //Msg.AskQuestion("帮助文档");
        }
        public virtual void DoDelete(IButtonInfo sender)
        {
            //Msg.AskQuestion("帮助文档");
        }
        public virtual void DoEdit(IButtonInfo sender)
        {
            //Msg.AskQuestion("帮助文档");
        }
        public virtual void DoSave(IButtonInfo sender)
        {
            //Msg.AskQuestion("帮助文档");
        }
        public virtual void DoCancel(IButtonInfo sender)
        {
            //Msg.AskQuestion("帮助文档");
        }
        public virtual void DoHelp(IButtonInfo sender)
        {
            //Msg.AskQuestion("帮助文档");
        }
        public virtual void DoReturn(IButtonInfo sender)
        {
            //Msg.AskQuestion("帮助文档");
        }
        public virtual void DoCalculate(IButtonInfo sender)
        {
           
        }
        public virtual void DoSJ(IButtonInfo sender)
        {

        }
        public virtual void DoSTD(IButtonInfo sender)
        {

        }
        public virtual void DoMachineTime(IButtonInfo sender)
        {
           
        }
        public virtual void DoImport(IButtonInfo sender)
        {

        }
        public virtual void DoExport(IButtonInfo sender)
        {

        }
        public virtual void DoPrint(IButtonInfo sender)
        {

        }
        public virtual void DoUnCheck(IButtonInfo sender)
        {

        }
        public virtual void DoCheck(IButtonInfo sender)
        {

        }
        public virtual void DoUpLoad(IButtonInfo sender)
        {

        }
        public virtual void DoIEExportUpLoad(IButtonInfo sender)
        {

        }
        public virtual void DoIECalcuate(IButtonInfo sender)
        {

        }
        public virtual void DOChange(IButtonInfo sender)
        {

        }
        public virtual void DoClose(IButtonInfo sender)
        {
            this.Close();
        }
        public virtual void DoResetCom(IButtonInfo sender)
        {

        }
        public virtual void DoUpLoadSAP(IButtonInfo sender)
        {

        }
        public virtual void DOStaffConfigure(IButtonInfo sender)
        {

        }
        public virtual void DoFeatureImport(IButtonInfo sender)
        {

        }

        public virtual void DoUnLocked(IButtonInfo sender)
        {
        }
        public virtual void DoApproval(IButtonInfo sender)
        {



        }



        public virtual void DoDeclare(IButtonInfo sender)
        {

        }
        public virtual void DoBack(IButtonInfo sender)
        {

        }


        #region"可扩展按钮"
        public virtual void DoButton1(IButtonInfo sender)
        {

        }
        public virtual void DoButton2(IButtonInfo sender)
        {

        }
        public virtual void DoButton3(IButtonInfo sender)
        {

        }
        public virtual void DoButton4(IButtonInfo sender)
        {

        }
        public virtual void DoButton5(IButtonInfo sender)
        {

        }
        public virtual void DoButton6(IButtonInfo sender)
        {

        }
        
        #endregion
        public virtual bool AllowMultiInstatnce { get { return _AllowMultiInstance; } set { _AllowMultiInstance = value; } }
        #endregion

        private void frmBaseChild_FormClosed(object sender, FormClosedEventArgs e)
        {
            GC.Collect();
            NotifyObserver();
        }
        private void NotifyObserver()
        {
            //foreach (IObserver o in _observers)
            //{  if(o!=null)
            //    o.Notify();
            //}
            this.ToolbarRegister.Dispose();
        }

        private void frmBaseChild_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.IsClosing = true; //正在关闭状态
        }

        private void frmBaseChild_Activated(object sender, EventArgs e)
        {
            this.RegisterToolBar(this.ToolbarRegister);
            this.NotifyObserver(); //通过其它观察者
        }
        
    }
}
